import Vue from "vue"
import NProgress from "nprogress"
import VueRouter from "vue-router"

const globModules = import.meta.globEager("@/router/modules/*.js")
const routes = Object.values(globModules).reduce((modules, module) => {
  return [...modules, ...module.default]
}, [])

const router = new VueRouter({
  base: window.env.staticPath,
  mode: "history",
  routes,
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  next()
})

router.afterEach(() => {
  NProgress.done()
})

Vue.use(VueRouter)

export default router
